<?php
// +----------------------------------------------------------------------
// | Variable 自定义服务
// +----------------------------------------------------------------------
// | 主要服务于Variable数据处理
// +----------------------------------------------------------------------
// | 错误编码头 230xxx
// +----------------------------------------------------------------------

namespace common\service;


use common\model\AttributeModel;
use common\model\AttributeValueModel;

class DataSourceService
{

    /**
     * 获取字段数据源
     * @param $dataSourceName
     * @return array|void
     */
    public function getFieldDataSource($dataSourceName)
    {

        if (strpos($dataSourceName, 'attribute_') !== false) {
            list(, $attributeCode) = explode('attribute_', $dataSourceName);
            return $this->getAttributeList($attributeCode);
        }

        $dataSourceNameCapitalize = ucfirst($dataSourceName);
        $methodName = "get{$dataSourceNameCapitalize}List";

        if (!method_exists($this, $methodName)) {
            return [];
        } else {
            return $this->{$methodName}();
        }
    }

    /**
     * 属性值
     * @param $attributeCode
     * @return array|mixed
     */
    protected function getAttributeList($attributeCode)
    {
        $attributeModel = model(AttributeModel::class);
        $attributeValueModel = model(AttributeValueModel::class);

        $attributeId = $attributeModel->where(['code' => $attributeCode])->getField("id");
        if (empty($attributeId)) {
            return [];
        }

        $attributeList = $attributeValueModel->where(['attribute_id' => $attributeId])->field("id,value")->select();

        return $attributeList;
    }

    /**
     * 获取发布平台列表
     * @return array
     */
    protected function getProjectDeliveryPlatformList()
    {
        return [
            'tencent' => '腾讯',
            'youku' => '优酷',
            'iqiyi' => '爱奇艺',
            'mango_tv' => '芒果TV'
        ];
    }

    /**
     * 项目分辨率数据源
     * @return array
     */
    protected function getProjectResolutionList()
    {
        return [
//            "3656x3112" => "root.format",
            "640x480" => "PC_Video",
            "720x486 0.91" => "NTSC",
            "720x576 1.09" => "PAL",
            "720x486 1.21" => "NTSC_16:9",
            "720x576 1.46" => "PAL_16:9",
            "1280x720" => "HD_720",
            "1920x1080" => "HD_1080",
            "3840x2160" => "UHD_4K",
            "1024x778" => "1K_Super_35(full-ap)",
            "914x778 2" => "1K_Cinemascope",
            "2048x1556" => "2K_Super_35(full-ap)",
            "1828x1556 2" => "2K_Cinemascope",
            "2048x1080" => "2K_DCP",
            "4096x3112" => "4K_Super_35(full-ap)",
            "3656x3112 2" => "4K_Cinemascope",
            "4096x2160 2" => "4K_DCP",
            "256x256" => "square_256",
            "512x512" => "square_512",
            "1024x1024" => "square_1K",
            "2048x2048" => "square_2K",
            "2048x1024" => "2K_LatLong",
            "4096x2048" => "4K_LatLong",
            "6144x3072" => "6K_LatLong",
            "8192x4096" => "8K_LatLong",
            "2048x1536" => "2K_CubeMap",
            "4086x3072" => "4K_CubeMap",
            "6144x4608" => "6K_CubeMap",
            "8192x6144" => "8K_CubeMap",
        ];
    }

    /**
     * 公开数据源
     * @return array
     */
    protected function getProjectPublicList()
    {
        return [
            'yes' => "公开",
            'no' => "私有",
        ];
    }

    /**
     * 是否demo数据源
     */
    protected function getProjectIsDemoList()
    {
        return [
            'yes' => "是",
            'no' => "否",
        ];
    }

    /**
     * 日历类型数据源
     * @return array
     */
    protected function getCalendarTypeList()
    {
        return [
            'holiday' => "节日日历",
            'event' => "活动日历",
            'overtime' => "加班日历",
        ];
    }

    /**
     * 字段类型数据源
     * @return array
     */
    protected function getFieldTypeList()
    {
        return [
            'built_in' => "内置",
            'custom' => "自定义",
        ];
    }

    /**
     * 字段是自定义字段数据源
     * @return array
     */
    protected function getFieldIsHorizontalList()
    {
        return [
            '0' => "否",
            '1' => "是"
        ];
    }


    /**
     * 过滤器颜色数据源
     * @return array
     */
    protected function getFilterColorList()
    {
        return [
            'red' => "红色",
            'orange' => "橙色",
            'olive' => "褐色",
            'green' => "绿色",
            'teal' => "青色",
            'blue' => "蓝色",
            'violet' => "蓝紫色",
            'purple' => "紫色",
            'pink' => "粉色",
            'brown' => "棕色",
            'grey' => "灰色",
            'black' => "灰色",
        ];
    }

    /**
     * 过滤器是否公开数据源
     * @return array
     */
    protected function getFilterPublicList()
    {
        return [
            'yes' => '公开',
            'no' => '隐私',
        ];
    }

    /**
     * LDAP是否打开ssl数据源
     * @return array
     */
    protected function getLdapSslList()
    {
        return [
            '0' => "关闭",
            '1' => "开启",
        ];
    }

    /**
     * LDAP是否打开Tsl数据源
     * @return array
     */
    protected function getLdapTlsList()
    {
        return [
            '0' => "关闭",
            '1' => "开启",
        ];
    }

    /**
     * 模块类型数据源
     * @return array
     */
    protected function getModuleTypeList()
    {
        return [
            'entity' => "实体",
            'fixed' => "项目固定模块",
        ];
    }

    /**
     * 模块激活状态数据源
     * @return array
     */
    protected function getModuleActiveList()
    {
        return [
            'yes' => "激活",
            'no' => "未激活",
        ];
    }

    /**
     * 模块关联关系类型数据源
     * @return array
     */
    protected function getModuleRelationTypeList()
    {
        return [
            'has_one' => "一对一",
            'belong_to' => "归属于",
            'has_many' => "一对多",
            'many_to_many' => "多对多"
        ];
    }

    /**
     * 配置类型数据源
     * @return array
     */
    protected function getOptionsTypeList()
    {
        return [
            'system' => "系统"
        ];
    }

    /**
     * 角色类型数据源
     * @return array
     */
    protected function getRoleTypeList()
    {
        return [
            'system' => "系统",
            'custom' => "自定义",
        ];
    }

    /**
     * 数据结构类型数据源
     * @return array
     */
    protected function getSchemaTypeList()
    {
        return [
            'system' => "system",
            'page' => "page",
        ];
    }

    /**
     * 状态从属关系 数据源
     * @return array
     */
    protected function getStatusCorrespondList()
    {
        return [
            'blocked' => "停滞",
            'not_started' => "未开始",
            'in_progress' => "进行中",
            'daily' => "日常",
            'feedback' => "反馈",
            'done' => "已完成",
            'hide' => "隐藏",
        ];
    }

    /**
     * 标签类型数据源
     * @return array
     */
    protected function getTagTypeList()
    {
        return [
            'system' => "系统 ",
            'review' => "审查",
            'approve' => "通过",
            'publish' => "发布",
            'custom' => "自定义",
            'liber' => "自由的",
        ];
    }

    /**
     * 任务类型数据源
     * @return array
     */
    protected function getTaskTypeList()
    {
        return [
            'normal' => "普通",
            'shadow' => "影子",
            'sub' => "子任务",
        ];
    }

    /**
     * 租户状态数据源
     * @return array
     */
    protected function getTenantStatusList()
    {
        return [
            'active' => "激活",
            'invalid' => "非法",
        ];
    }

    /**
     * 用户配置类型数据源
     * @return array
     */
    protected function getUserConfigTypeList()
    {
        return [
            'system' => "系统",
            'reminder' => "提醒",
            'filter_stick' => "滤棒",
            'add_panel' => "添加面板",
            'update_panel' => "更新面板",
            'top_field' => "顶部字段",
        ];
    }


    /**
     * 试图公开类型数据源
     * @return array
     */
    protected function getViewPublicList()
    {
        return [
            'yes' => "公开",
            'no' => "私有"
        ];
    }

}
